package com.xt.back.constant;


import lombok.Data;

/**
 * @author 小童
 * @date 2021/7/21
 */

@Data
public class ResultDTO<T> {
    private int code;

    private String msg;

    private T data;

    private ResultDTO(int Code, String message, T data){
        this.code=Code;
        this.msg=message;
        this.data=data;
    }

    public static<T> ResultDTO<T> success(T obj) {
        return new ResultDTO<>(APIStatusCodeEnum.SUCCESS.getCode(), APIStatusCodeEnum.SUCCESS.getMsg(), obj);
    }

    public static<T> ResultDTO<T> success(String msg, T obj) {
        return new ResultDTO<>(APIStatusCodeEnum.SUCCESS.getCode(), msg, obj);
    }


    /**
     * 500 系统错误（后端异常）
     */
    public static<T> ResultDTO<T> error() {
        return new ResultDTO<>(APIStatusCodeEnum.ERROR.getCode(), APIStatusCodeEnum.ERROR.getMsg(), null);
    }

    public static<T> ResultDTO<T> error(T obj) {
        return new ResultDTO<>(APIStatusCodeEnum.ERROR.getCode(), APIStatusCodeEnum.ERROR.getMsg(), obj);
    }

    public static<T> ResultDTO<T> error(String msg, T obj) {
        return new ResultDTO<>(APIStatusCodeEnum.ERROR.getCode(), msg, obj);
    }

    public static<T> ResultDTO<T> error(String msg) {
        return new ResultDTO<>(APIStatusCodeEnum.ERROR.getCode(), msg, null);
    }

    /**
     * 400 失败客户端错误
     */
    public static<T> ResultDTO<T> failure(String msg) {
        return new ResultDTO<>(APIStatusCodeEnum.PARAMETER_ERROR.getCode(),msg, null);
    }

    public static<T> ResultDTO<T>failure(T obj) {
        return new ResultDTO<>(APIStatusCodeEnum.PARAMETER_ERROR.getCode(), APIStatusCodeEnum.PARAMETER_ERROR.getMsg(), obj);
    }

    public static<T> ResultDTO<T> failure(String msg, T obj) {
        return new ResultDTO<>(APIStatusCodeEnum.PARAMETER_ERROR.getCode(), msg, obj);
    }


    /**
     * 403
     * 未登录
     * 没有权限
     */
    public static<T> ResultDTO<T> forbidden() {
        return new ResultDTO<>(APIStatusCodeEnum.FORBIDDEN.getCode(), APIStatusCodeEnum.FORBIDDEN.getMsg(), null);
    }

    public static<T> ResultDTO<T> forbidden(T obj) {
        return new ResultDTO<>(APIStatusCodeEnum.FORBIDDEN.getCode(), APIStatusCodeEnum.FORBIDDEN.getMsg(), obj);
    }

    public static<T> ResultDTO<T> forbidden(String msg, T obj) {
        return new ResultDTO<>(APIStatusCodeEnum.FORBIDDEN.getCode(), msg, obj);
    }

    public static<T> ResultDTO<T> forbidden(String msg) {
        return new ResultDTO<>(APIStatusCodeEnum.FORBIDDEN.getCode(), msg, null);
    }





}
